import logging

import pytest

from resource.pom.keyboard import Keyboard
from resource.pom.memorandum import Memorandum


class Test:
    app = Memorandum
    keyboard = Keyboard

    @pytest.mark.parametrize('setup_teardown', [app.bundle_name], indirect=True)
    def test(self, setup_teardown, device):
        logging.info('预置条件.清除测试数据')
        device.hdc_shell('rm -rf /data/app/el2/100/database/com.ohos.note/default/rdb/note.db')
        device.wait(2)
        logging.info('步骤1.进入桌面，点击备忘录应用，点击搜索笔记框输入要搜索的内容')
        device.start_ability(self.app.bundle_name, self.app.ability_name)
        device.refresh_layout()
        search_area = device.get_element_by_key('searchInput')
        device.click_element(search_area)
        device.click(*self.keyboard.key_u)
        device.click(*self.keyboard.key_x)
        logging.info('预期结果1.点击搜素框可唤醒键盘，显示无遮挡，搜索显示结果与搜索框输入的关键词一致')
        device.refresh_layout()
        device.assert_soft_keyboard_on()
        _, search_area_y = device.center_of_element(device.get_element_by_key('searchInput'))
        _, meeting_y = device.center_of_element(device.get_element_by_text('UX会议纪要'))
        keyboard_area = device.soft_keyboard_area()
        logging.info('搜索框的y坐标为{}，UX会议纪要的y坐标为{}，键盘的y为{}'.format(search_area_y, meeting_y, keyboard_area['y']))
        assert search_area_y < meeting_y < keyboard_area['y'], '显示有遮挡'
